﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Quizzer.Model;

namespace Quizzer.DataAccess
{
    public static class QuestionRepository
    {
        readonly static Dictionary<Guid, Question> _questions;

        static QuestionRepository()
        {
            _questions = LoadQuestions();
        }

        static Dictionary<Guid, Question> LoadQuestions()
        {
            return Question.Items;
        }

        public static ObservableCollection<Question> GetQuestionsOfTest(Test test)
        {
            var query = from question in _questions.Values
                        where question.TestID == test.Id
                        select question;

            return new ObservableCollection<Question>(query.ToList());
        }

        public static Question GetQuestion(Question question)
        {
            if (_questions.Keys.Contains(question.Id))
                return _questions[question.Id];
            else
                return null;
        }
    }
}
